//
//  HHPHTTPRequest.h
//  HHPHTTPRequest
//
//  Created by 韩红坡 on 2016/12/13.
//  Copyright © 2016年 韩红坡. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "HHPHTTPRequestOptions.h"

#define HHPHTTPRequestException @"HHPHTTPRequestException"

@interface HHPHTTPRequest : NSObject

/** 
 * 不要自己初始化这个类
 * 请使用HHPHTTPRequestManager的-createRequest方法
 */
- (instancetype)initWithSessionManager:(AFHTTPSessionManager *)sessionManager;

/** get或post方法 */
@property (nonatomic, assign) HHPHTTPMethod method;
/** 请求的绝对地址 */
@property (nonatomic, strong) NSString *url;
/** 请求选项 */
@property (nonatomic, strong, readonly) HHPHTTPRequestOptions *options;
/** 只读的参数 */
@property (nonatomic, strong, readonly) NSDictionary<NSString *, id> *params;
/** 只读的请求头 */
@property (nonatomic, strong, readonly) NSDictionary<NSString *, NSString *> *headers;
/** 调用了-startWithSuccess:error:方法前，此属性为nil */
@property (nonatomic, strong, readonly) NSURLSessionTask *task;
/** 请求返回的数据 */
@property (nonatomic, strong, readonly) id data;
/** 返回的错误 */
@property (nonatomic, strong, readonly) NSError *error;

/** 设置一个参数 */
- (void)setParam:(NSString *)name value:(id)value;
/** 批量设置参数 */
- (void)setParams:(NSDictionary<NSString *, id> *)params;
/** 设置请求头 */
- (void)setHeader:(NSString *)name value:(NSString *)value;
/** 批量设置请求头 */
- (void)setHeaders:(NSDictionary<NSString *, NSString *> *)headers;
/** 多用于上传文件 */
- (void)setConstructingBodyBlock:(void (^)(id <AFMultipartFormData> formData))block;

/** 
 * 发起请求
 * successBlock : 成功回调
 * errorBlock   : 失败回调
 */
- (void)startWithSuccess:(void (^)(HHPHTTPRequest *request))successBlock
                   error:(void (^)(HHPHTTPRequest *request))errorBlock;

/**
 * 发起请求
 * progressBlock : 进度回调
 * successBlock  : 成功回调
 * errorBlock    : 失败回调
 */
- (void)startWithProgress:(void (^)(HHPHTTPRequest *request, NSProgress *progress))progressBlock
                  success:(void (^)(HHPHTTPRequest *request))successBlock
                    error:(void (^)(HHPHTTPRequest *request))errorBlock;

// 取消请求
- (void)cancel;

@end
